package View;

import java.awt.*;
import java.awt.event.ActionListener;

import javax.swing.*;
import javax.swing.border.*;
/*
 * Created by JFormDesigner on Fri Dec 16 22:23:24 ICT 2011
 */

import Entity.User;



/**
 * @author Khainx
 */
public class LoginView extends JPanel {
	public LoginView() {
		initComponents();
	}

	private void initComponents() {
		// JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents
		panel1 = new JPanel();
		label1 = new JLabel();
		label4 = new JLabel();
		label6 = new JLabel();
		label2 = new JLabel();
		txtUsername = new JTextField();
		label7 = new JLabel();
		label3 = new JLabel();
		txtPassword = new JPasswordField();
		label5 = new JLabel();
		panel2 = new JPanel();
		btnLogin = new JButton();
		btnExit = new JButton();

		//======== this ========
		setPreferredSize(new Dimension(300, 170));
		setLayout(new BorderLayout());

		//======== panel1 ========
		{
			panel1.setPreferredSize(new Dimension(120, 125));
			panel1.setLayout(new GridBagLayout());
			((GridBagLayout)panel1.getLayout()).columnWidths = new int[] {0, 0, 0, 0, 0};
			((GridBagLayout)panel1.getLayout()).rowHeights = new int[] {0, 0, 0, 0, 0, 0};
			((GridBagLayout)panel1.getLayout()).columnWeights = new double[] {0.0, 0.0, 1.0, 0.0, 1.0E-4};
			((GridBagLayout)panel1.getLayout()).rowWeights = new double[] {0.0, 0.0, 0.0, 0.0, 0.0, 1.0E-4};

			//---- label1 ----
			label1.setText("\u0110\u0103ng nh\u1eadp");
			label1.setPreferredSize(new Dimension(120, 60));
			label1.setFont(new Font("Tahoma", Font.BOLD, 18));
			panel1.add(label1, new GridBagConstraints(1, 0, 2, 1, 0.0, 0.0,
				GridBagConstraints.CENTER, GridBagConstraints.VERTICAL,
				new Insets(0, 0, 5, 5), 0, 0));

			//---- label4 ----
			label4.setText(" ");
			panel1.add(label4, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0,
				GridBagConstraints.CENTER, GridBagConstraints.BOTH,
				new Insets(0, 0, 5, 5), 0, 0));

			//---- label6 ----
			label6.setText(" ");
			panel1.add(label6, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0,
				GridBagConstraints.CENTER, GridBagConstraints.BOTH,
				new Insets(0, 0, 5, 5), 0, 0));

			//---- label2 ----
			label2.setText("T\u00ean \u0111\u0103ng nh\u1eadp:");
			panel1.add(label2, new GridBagConstraints(1, 2, 1, 1, 0.0, 0.0,
				GridBagConstraints.CENTER, GridBagConstraints.BOTH,
				new Insets(0, 0, 5, 5), 0, 0));

			//---- txtUsername ----
			txtUsername.setPreferredSize(new Dimension(91, 20));
			panel1.add(txtUsername, new GridBagConstraints(2, 2, 1, 1, 0.0, 0.0,
				GridBagConstraints.CENTER, GridBagConstraints.BOTH,
				new Insets(0, 0, 5, 5), 0, 0));

			//---- label7 ----
			label7.setText(" ");
			panel1.add(label7, new GridBagConstraints(3, 2, 1, 1, 0.0, 0.0,
				GridBagConstraints.CENTER, GridBagConstraints.BOTH,
				new Insets(0, 0, 5, 0), 0, 0));

			//---- label3 ----
			label3.setText("M\u1eadt kh\u1ea9u:");
			panel1.add(label3, new GridBagConstraints(1, 3, 1, 1, 0.0, 0.0,
				GridBagConstraints.CENTER, GridBagConstraints.BOTH,
				new Insets(0, 0, 5, 5), 0, 0));

			//---- txtPassword ----
			txtPassword.setPreferredSize(new Dimension(91, 20));
			panel1.add(txtPassword, new GridBagConstraints(2, 3, 1, 1, 0.0, 0.0,
				GridBagConstraints.CENTER, GridBagConstraints.BOTH,
				new Insets(0, 0, 5, 5), 0, 0));

			//---- label5 ----
			label5.setText(" ");
			panel1.add(label5, new GridBagConstraints(1, 4, 1, 1, 0.0, 0.0,
				GridBagConstraints.CENTER, GridBagConstraints.BOTH,
				new Insets(0, 0, 0, 5), 0, 0));
		}
		add(panel1, BorderLayout.CENTER);

		//======== panel2 ========
		{
			panel2.setLayout(new FlowLayout());

			//---- btnLogin ----
			btnLogin.setText("\u0110\u0103ng nh\u1eadp");
			panel2.add(btnLogin);

			//---- btnExit ----
			btnExit.setText("Tho\u00e1t");
			panel2.add(btnExit);
		}
		add(panel2, BorderLayout.SOUTH);
		// JFormDesigner - End of component initialization  //GEN-END:initComponents
	}

	// JFormDesigner - Variables declaration - DO NOT MODIFY  //GEN-BEGIN:variables
	private JPanel panel1;
	private JLabel label1;
	private JLabel label4;
	private JLabel label6;
	private JLabel label2;
	private JTextField txtUsername;
	private JLabel label7;
	private JLabel label3;
	private JPasswordField txtPassword;
	private JLabel label5;
	private JPanel panel2;
	private JButton btnLogin;
	private JButton btnExit;
	// JFormDesigner - End of variables declaration  //GEN-END:variables
	public void doLogin(ActionListener listener){
		this.btnLogin.addActionListener(listener);
	}
	public void doExit(ActionListener listener){
		this.btnExit.addActionListener(listener);
	}
//	public boolean RememberPW(){
//		return chkRP.isSelected();
//	}
	public User getUser(){
		User user = new User("","");
		user.setUsername(txtUsername.getText());
		user.setPassword(new String(txtPassword.getPassword()));
		return user;
	}
	public void Display(User user){
		txtUsername.setText(user.getUsername());
		txtPassword.setText(user.getPassword());
	}
}
